package com.mediacloud.app.newsmodule.activity.microlive;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.View;

import com.mediacloud.app.newsmodule.R;
import com.mediacloud.app.newsmodule.microlive.Lives;
import com.mediacloud.app.newsmodule.utils.GridLayoutSpanCountUtils;

/**
 */

public class MicroLiveNineGridImageHolder extends MicroLiveDetailItemBaseViewHolder
{
    private final GridLayoutManager gridLayoutManager;
    RecyclerView gridView;
    JJYYGridAdapter jjyyGridAdapter;
//    public final View vertical_line_2;

    public MicroLiveNineGridImageHolder(View itemView,@IMicroDetailDataObj.LiveType int liveType)
    {
        super(itemView, liveType);
        gridView=itemView.findViewById(R.id.gridView);
//        vertical_line_2 = itemView.findViewById(R.id.vertical_line_2);
        jjyyGridAdapter=new JJYYGridAdapter(itemView.getContext());
        gridLayoutManager=new GridLayoutManager(itemView.getContext(),3);
        gridLayoutManager.setOrientation(GridLayoutManager.VERTICAL);
        gridView.setLayoutManager(gridLayoutManager);
        gridView.addItemDecoration(new XdNineGridDivider(itemView.getContext().getResources().getDimensionPixelSize(R.dimen.dimen5)));
        gridView.setAdapter(jjyyGridAdapter);
        gridView.setVerticalScrollBarEnabled(false);
        gridView.setNestedScrollingEnabled(false);
//        vertical_line_2.setPaddingRelative(0, (int) itemView.getResources().getDimension(R.dimen.dimen10),0,0);
//        vertical_line_2.setBackgroundColor(itemView.getResources().getColor(R.color._color_jnsb));
    }


    @Override
    public void setItemData(Lives data)
    {
        super.setItemData(data);
        jjyyGridAdapter.articleItem=articleItem;
        subLayout.setVisibility(View.GONE);
        jjyyGridAdapter.getData().clear();
        if(data.getImage()!=null&&data.getImage().size()>0)
        {
            gridLayoutManager.setSpanCount(GridLayoutSpanCountUtils.calculateSpanCount(data.getImage().size()));
            gridLayoutManager.requestLayout();
            jjyyGridAdapter.getData().addAll(data.getImage());
            appfacHandle();
        }
        jjyyGridAdapter.notifyDataSetChanged();
    }

    private void appfacHandle()
    {
        int ptop=0;
        if(publishTitle.getVisibility()==View.GONE)
            ptop=itemView.getResources().getDimensionPixelOffset(R.dimen.dime_nine);
        gridView.setPaddingRelative(gridView.getPaddingStart(),ptop,gridView.getPaddingEnd(),gridView.getPaddingBottom());
    }
}